<?php

require_once 'Smarty3/Smarty.class.php';

class Smarty_View extends Zend_View_Abstract {
	
	protected $_pluginDirs;
	
	public function init()
	{
		$dirs = glob('modules/*/views/plugins', GLOB_ONLYDIR);
		$this->_pluginDirs = array_map('realpath', $dirs);
	}
	
	protected function _run() {
		$script = realpath(func_get_arg(0));
		if (!empty($script)) {
			$smarty = new Smarty();
			$smarty->_file_perms = 0666;
			$smarty->error_reporting = E_ALL;
			if (preg_match('@^.*/([^/]+)/views/scripts/@', $script, $path)) {
				$smarty->compile_id = $path[1];
				$smarty->template_dir = $path[0];
			} else {
				$smarty->template_dir = dirname($script);
			}
			$smarty->compile_dir = 'temp/templates_c';
			$smarty->addPluginsDir($this->_pluginDirs);
			$smarty->assign($this->getVars());
			$smarty->assignByRef('this', $this);
			$smarty->display($script);
		}
	}

}